﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Website
{
    public partial class KaartjesKiezen : System.Web.UI.Page
    {
        private Voorstelling v;
        public bool driedfilm = false;

        protected void Page_Load(object sender, EventArgs e)
        {
            v = (Voorstelling)Session["voorstelling"];

            if (v == null)
            {
                Response.Redirect("Startpagina.aspx");
            }
            else
            {              
                initComponents();
            }
            AdultCounter.Attributes.Add("readonly", "readonly");
            ChildCounter.Attributes.Add("readonly", "readonly");
            OldPeopleCounter.Attributes.Add("readonly", "readonly");
            StudentCounter.Attributes.Add("readonly", "readonly");
            drieCounter.Attributes.Add("readonly", "readonly");      
        }

        private void initComponents()
        {
            FilmPosterInfo filmPosterInfo = (FilmPosterInfo)LoadControl("FilmPosterInfo.ascx");
            filmPosterInfo.setgetFilm = v.Film;
            Panel_FilmPosterInfo.Controls.Add(filmPosterInfo);
               

            if (ViewState["adultcounter"] == null)       { ViewState["adultcounter"] = 0; }
            if (ViewState["childcounter"] == null)       { ViewState["childcounter"] = 0; }
            if (ViewState["50pluscounter"] == null)      { ViewState["50pluscounter"] = 0; }
            if (ViewState["studentcounter"] == null)     { ViewState["studentcounter"] = 0; }
            if (ViewState["3dglassescounter"] == null)   { ViewState["3dglassescounter"] = 0; }

            if (v.Film._3d == false)
            {
            driedfilm = false;
            }
            else
            {
            driedfilm = true;
            }     
       
            checkCount();
        }

        //Totaal aantal geselecteerde kaarten controleren.
        private void checkCount()
        {
            int count = (int)ViewState["adultcounter"] + (int)ViewState["childcounter"] + (int)ViewState["50pluscounter"] +
                        (int)ViewState["studentcounter"] + (int)ViewState["3dglassescounter"];

            if (count > 0)
            {
                ButtonDirectKopen.Enabled = true;
                ButtonReserveren.Enabled = true;
            }
            else
            {
                ButtonReserveren.Enabled = false;
                ButtonDirectKopen.Enabled = false;
            }
        }


        protected void ButtonDirectKopen_Click(object sender, EventArgs e)
        {
            Session["adults"] = Convert.ToInt32(AdultCounter.Text);
            Session["childeren"] = Convert.ToInt32(ChildCounter.Text);
            Session["50plus"] = Convert.ToInt32(OldPeopleCounter.Text);
            Session["students"] = Convert.ToInt32(StudentCounter.Text);
            Session["3dglasses"] = Convert.ToInt32(drieCounter.Text);
            Session["bestelwijze"] = "Direct kopen";

            Response.Redirect("StoelenKiezen.aspx");
        }

        protected void ButtonReserveren_Click(object sender, EventArgs e)
        {
            Session["adults"] = Convert.ToInt32(AdultCounter.Text);
            Session["childeren"] = Convert.ToInt32(ChildCounter.Text);
            Session["50plus"] = Convert.ToInt32(OldPeopleCounter.Text);
            Session["students"] = Convert.ToInt32(StudentCounter.Text);
            Session["3dglasses"] = Convert.ToInt32(drieCounter.Text);
            Session["bestelwijze"] = "Reserveren";

            Response.Redirect("StoelenKiezen.aspx");
        }
    }
}